package com.liucxu.jiandanl.View.Adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.liucxu.jiandanl.Config.ImageLoaderUtils;
import com.liucxu.jiandanl.Entity.PicComments;
import com.liucxu.jiandanl.R;
import com.liucxu.jiandanl.Utils.ViewHolder;
import com.liucxu.jiandanl.View.Fragment.BoringPicsFragment;
import com.liucxu.jiandanl.Widget.ShowMaxWidthImageView;

import java.util.ArrayList;
import java.util.List;

/**
 * 无聊图的Adapter
 * Created by liuchenxu on 2016/8/4.
 */
public class BoringPicAdapter extends BaseAdapter {

    private List<PicComments> items;

    private BoringPicsFragment mContext;

    public BoringPicAdapter(BoringPicsFragment context) {
        items = new ArrayList<PicComments>();
        mContext = context;
    }

    public void setDatas(List<PicComments> datas) {
        if (datas != null) {
            items.clear();
            items.addAll(datas);
            notifyDataSetChanged();
        }
    }

    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public Object getItem(int i) {
        return items.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = View.inflate(mContext.getActivity(), R.layout.adapter_boring_pics, null);
        }
        initView(view,i);
        return view;
    }

    /**
     *
     * @param view
     * @param position
     */
    private void initView(View view,int position) {
        PicComments post=items.get(position);
        ShowMaxWidthImageView img=ViewHolder.get(view,R.id.adapter_img);
        TextView adapter_author=ViewHolder.get(view,R.id.adapter_author);
        TextView adapter_positive=ViewHolder.get(view,R.id.adapter_positive);
        TextView adapter_negative=ViewHolder.get(view,R.id.adapter_negative);
//        if(post.getPics().get(0).endsWith(".gif")){
//            GlideUtils.getInstance().LoadSupportv4FragmentBitmap(mContext,post.getPics().get(0),img,R.drawable.ic_loading_large,R.drawable.ic_loading_large,GlideUtils.LOAD_GIF);
//        }
//        else{
//            GlideUtils.getInstance().LoadSupportv4FragmentBitmap(mContext,post.getPics().get(0),img,R.drawable.ic_loading_large,R.drawable.ic_loading_large,GlideUtils.LOAD_BITMAP);
//        }

        adapter_author.setText(post.getComment_author());
        adapter_positive.setText("OO "+post.getVote_positive());
        adapter_negative.setText("XX "+post.getVote_negative());
        ImageLoaderUtils.displayImageWithLoadingPicture(post.getPics().get(0),img);
//        artical_title.setText(post.getTitle());
//        adapter_author.setText(post.getAuthor().getNickname());
//        adapter_chanel.setText("@"+post.getTags().get(0).getTitle());
//        adapter_brow_num.setText("浏览"+post.getTags().get(0).getPost_count()+"次");
//        adapter_share.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                final Dialog dialog = new Dialog(mContext.getActivity(),"分享", "确认分享?");
//                dialog.setOnAcceptButtonClickListener(new View.OnClickListener(){
//                    @Override
//                    public void onClick(View view) {
//                        dialog.dismiss();
//                    }
//                });
//                dialog.setOnCancelButtonClickListener(new View.OnClickListener(){
//                    @Override
//                    public void onClick(View view) {
//                        dialog.dismiss();
//                    }
//                });
//            }
//        });
    }
}
